package com.huatai.user.controller;

import com.huatai.common.api.R;
import com.huatai.common.controller.BaseController;
import com.huatai.common.log.annotation.Log;
import com.huatai.common.log.enums.BusinessType;
import com.huatai.user.entity.LogoManager;
import com.huatai.user.service.LogoManagerService;
import com.huatai.user.service.impl.LogoFileService;
import com.huatai.user.vo.LogoManagerVo;
import com.huatai.user.vo.UploadlogoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @program: ht-system
 * @description: logo管理控制器
 * @author: zsj
 * @create: 2023-02-02 15:30
 **/
@Validated
@RestController
@RequestMapping("/logo")
@Api(value = "logo管理", tags = "logo管理")
public class LogoController extends BaseController {

	@Autowired
	LogoFileService logoFileService;

	@Autowired
	private LogoManagerService logoService;

	/**
	 * logo上传
	 *
	 * @param file
	 * @return
	 */
	@ApiOperation(value = "普通上传", notes = "普通文件上传，上传文件成功返回文件路径以及展示地址")
	@Log(title = "logo管理", businessType = BusinessType.UPLOAD)
	@PostMapping("/upload")
	public R<UploadlogoVo> upload(MultipartFile file) {
		return R.data(logoFileService.upload(file));
	}

	/**
	 * 保存图片地址
	 *
	 * @param logoManager
	 * @return
	 */
	@PostMapping("/save")
	@Log(title = "logo管理", businessType = BusinessType.INSERT)
	@ApiOperation(value = "保存或者修改logo", notes = "保存或者修改logo")
	public R logoSave(@RequestBody LogoManager logoManager) {
		return R.status(logoService.saveLogoManager(logoManager));
	}

	/**
	 * 查询logo基本信息
	 *
	 * @return
	 */
	@GetMapping("/selectLogo")
	@ApiOperation(value = "查询logo基本信息", notes = "查询logo基本信息")
	public R<LogoManagerVo> selectLogoManager() {
		return R.data(logoService.selectLogoManagerList());
	}

}
